home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1994 September / macformat-004.iso / Demos / Asymptote / Examples / Utility Scripts / calc_correlation_coeff < prev    next >
Encoding:
Text File  |  1994-06-15  |  443 b   |  15 lines  |  [TEXT/DWat]

  1. % Calculate the linear correlation coefficient (Pearson's r)
  2. % for the x and y vectors and store in the variable "r_cc"
  3. %  
  4. %            SUM( (x - mean(x)) - (y - mean(y)) )
  5. %   r_cc =  ____________________________________
  6. %          SQRT(sum((x - mean(x))^2)) SQRT(sum((y - mean(y))^2))
  7. %
  8. rpn <x mean - <y mean - * sum
  9. set r_cc v0(1)
  10. rpn <x mean - dup * sum
  11. set r_cc r_cc v0(1) sqrt /
  12. rpn <y mean - dup * sum
  13. set r_cc r_cc v0(1) sqrt /
  14.  
  15. close